function ykcalendar(){
  var stylenum=0;
  var yfyear, yfmonth, yfday;
  this.init=function(type){
		  stylenum++;
		  if(stylenum<2 && type==1){
			  $("head").append("<style type='text/css'>.yue_rili .yue_day li.future{cursor:pointer;} .yue_rili .yue_day li.future:hover{background:#eee;}</style>");
		  }
		  $(".lookrili").click(function(){
		    var url = '/time.json';//time_path + "js/time.json",
			data = {"product.pid" : $("#pid").val()},
			pid = $("#pid").val();
		
		$.getMyJSON(url,data,function(data){
			$(".mdxzan .mdcitylist a").remove();
			var obj = data.data[0];
			var objName = data.data[0][0].CITY;
			var objId = data.data[0][0].ID;
			//alert(objName)
			$(".mdxzan .mdcitylist").append("<a onclick='ykrili.getentityshop("+objId+","+pid+")' class='active' href='javascript:void(0)'>"+objName+"</a>")
			for(var i = 1; i < obj.length; i++){
				var CITY = obj[i].CITY;
				$(".mdxzan .mdcitylist").append("<a onclick='ykrili.getentityshop("+obj[i].ID+","+pid+")' href='javascript:void(0)'>"+CITY+"</a>")
			}
			$(".fixrilitmbg .mdxzan .mdcitylist a").click(function(){
				$(this).addClass("active").siblings("a").removeClass("active");
			});
			getEntityshop(objId,pid);
		});
	});
  }
  this.getjiazairili=function(dateTime, type){
	  stylenum++;
	  if(stylenum<2 && type==1){
		  $("head").append("<style type='text/css'>.yue_rili .yue_day li.future{cursor:pointer;} .yue_rili .yue_day li.future:hover{background:#eee;}</style>");
	  }
      $(".riliqiean1").remove();
	  $(".riliqiean2").remove();
	  $(".riliyear").before("<div class='riliqiean1'></div>");
	  $(".riliyear").after("<div class='riliqiean2'></div>");
	  jiazhairili(dateTime);
  }

  var jiazhairili=function(dateTime){
	  var today = new Date();
	  year = today.getFullYear();
	  month = today.getMonth()+1;
	  thisDay = today.getDate();
	  firstDay = today;
	  firstDay.setDate(1);
	  startDay = firstDay.getDay();
	  oldyear= today.getFullYear();
	  oldmonth= today.getMonth()+1;
	  $("#xlyear").empty();
	  for(var nian=year;nian<2100;nian++){
		  $("#xlyear").append("<option id='y_"+nian+"' value='"+nian+"'>"+nian+"</option>");
	  }
	  $("#xlmonth").empty();
	  for(var yuexl=1;yuexl<13;yuexl++){
		  $("#xlmonth").append("<option id='m_"+yuexl+"' value='"+yuexl+"'>"+yuexl+"</option>");
	  }
	  var xyyue=oldmonth-1;
	  //$("#xlmonth option:lt("+xyyue+")").attr("disabled",true);
	  chushirili(today,year,month,thisDay,startDay);
	  
	  if(dateTime) {
		  dateTime = dateTime.split('-');
		  today = new Date(dateTime[0]+"/"+dateTime[1]+"/01");
		  yfstartDay = today.getDay();
		  yfyear = parseInt(dateTime[0]);
		  yfmonth= parseInt(dateTime[1]);
		  yfday = parseInt(dateTime[2]);
		  var yfstart = 0;
		  if(yfmonth == month) {
			  yfstart = thisDay;
		  }
		  chushirili(today,yfyear,yfmonth,yfstart,yfstartDay);
	  }
	  
	  var today2,year2,month2,thisDay2,startDay2,today3,year3,month3,thisDay3,startDay3;
	
	  $(".riliqiean1").click(function(){
		  var xlnian2=$("#xlyear").val();
		  var xlyue2=$("#xlmonth").val();
		  $("#xlmonth option").removeAttr("disabled");
		  month3=Number(xlyue2)-1;
		  if(month3==0){
			  if(xlnian2==oldyear){
				  month=month3=xlyue2;
				  year=year3=xlnian2;
				  //$("#xlmonth option:lt("+xyyue+")").attr("disabled",true);
			  }else{
				  month=month3=12;
				  if(year3==oldyear){
					  //$("#xlmonth option:lt("+xyyue+")").attr("disabled",true);
				  }
			  }
			  year=year3=Number(xlnian2)-1;
			  if(year < 2016 && year3 < 2016) {
				  year= year3 = 2016;
			  }
		  }else{
			  if(xlnian2==oldyear){
				  //$("#xlmonth option:lt("+xyyue+")").attr("disabled",true);
				  if(xlyue2==oldmonth){
					  //month=month3=Number(xlyue2);
					  month=month3=Number(xlyue2)-1;
				  }else{
					  month=month3=Number(xlyue2)-1;
				  }
			  }else{
				  month=month3=Number(xlyue2)-1;
			  }
			  year=year3=Number(xlnian2);
		  }
		  $("#xlyear").val(year3);
		  $("#xlmonth").val(month3);
		  today3 = new Date(year3+"/"+month3+"/01");
		  startDay3 = today3.getDay();
		  if(year3==oldyear && month3==oldmonth){
		  	  chushirili(today3,year3,month3,thisDay,startDay3);
		  }else{
			  chushirili(today3,year3,month3,0,startDay3);
		  }
	  })
		
	  $(".riliqiean2").click(function(){
		  var xlnian2=$("#xlyear").val();
		  var xlyue2=$("#xlmonth").val();
		  $("#xlmonth option").removeAttr("disabled");
		  month3=Number(xlyue2)+1;
		  if(month3==13){
			  month=month3=1;
			  year=year3=Number(xlnian2)+1;
		  }else{
			  month=month3=Number(xlyue2)+1;
			  year=year3=xlnian2;
			  if(year==oldyear){
				  //$("#xlmonth option:lt("+xyyue+")").attr("disabled",true);
			  }
		  }
		  $("#xlyear").val(year3);
		  //alert(month3)
		  $("#xlmonth").val(month3);
		  today3 = new Date(year3+"/"+month3+"/01");
		  startDay3 = today3.getDay();
		  //chushirili(today3,year3,month3,0,startDay3);
		  if(year3==oldyear && month3==oldmonth){
		  	  chushirili(today3,year3,month3,thisDay,startDay3);
		  }else{
			  chushirili(today3,year3,month3,0,startDay3);
		  }
	  })
	
	  $("#xlyear").change(function(){
		  $("#xlmonth option").removeAttr("disabled");
		  var xlnian=$("#xlyear").val();
		  var xlyue=$("#xlmonth").val();
		  if(xlnian==oldyear){
			  if(xlyue<=oldmonth){
				  xlyue=oldmonth;
				  //$("#xlmonth option:lt("+xyyue+")").attr("disabled",true);
				  today2 = new Date(xlnian+"/"+xlyue+"/01");
				  month=month2=xlyue;
				  year=year2=xlnian;
				  startDay2 = today2.getDay();
				  chushirili(today2,year2,month2,thisDay,startDay2);
			  }else{
				  today2 = new Date(xlnian+"/"+xlyue+"/01");
				  month=month2=xlyue;
				  year=year2=xlnian;
				  startDay2 = today2.getDay();
				  chushirili(today2,year2,month2,0,startDay2);
			  }
		  }else{
			  today2 = new Date(xlnian+"/"+xlyue+"/01");
			  month=month2=xlyue;
			  year=year2=xlnian;
			  startDay2 = today2.getDay();
			  chushirili(today2,year2,month2,0,startDay2);
		  }
	  })
	
	  $("#xlmonth").change(function(){
		  var xlnian=$("#xlyear").val();
		  var xlyue=$("#xlmonth").val();
		  today2 = new Date(xlnian+"/"+xlyue+"/01");
		  month=month2=xlyue;
		  year=year2=xlnian;
		  if(xlnian==oldyear){
			  if(xlyue<=oldmonth){
				  //xlyue=oldmonth;
				  //$("#xlmonth option:lt("+xyyue+")").attr("disabled",true);
				  today2 = new Date(xlnian+"/"+xlyue+"/01");
				  month=month2=xlyue;
				  year=year2=xlnian;
				  startDay2 = today2.getDay();
				  chushirili(today2,year2,month2,thisDay,startDay2);
			  }else{
				  today2 = new Date(xlnian+"/"+xlyue+"/01");
				  month=month2=xlyue;
				  year=year2=xlnian;
				  startDay2 = today2.getDay();
				  chushirili(today2,year2,month2,0,startDay2);
			  }
		  }else{
			  today2 = new Date(xlnian+"/"+xlyue+"/01");
			  month=month2=xlyue;
			  year=year2=xlnian;
			  startDay2 = today2.getDay();
			  chushirili(today2,year2,month2,0,startDay2);
		  }
	  });
	
	  for(i=0;i<24;i++){
		  $(".zttimes").append("<option value='"+i+"'>"+i+"</option>");
	  };
	  for(i=0;i<60;i++){
		  $(".zttimef").append("<option value='"+i+"'>"+i+"</option>");
		  $(".zttimem").append("<option value='"+i+"'>"+i+"</option>");
	  };
	}
	
  var initRiData =function(year,month,thisDay,startDay){
	//beg 通过json改变日历
	//console.log(0);
	jQuery.get("/time.txt",
			{
			   
			}, function (data) {
				 //alert(data[0]["args2"])
				data = eval(data);
				 DATEINFO=data[0]["args1"];
				 DATEREVINFO=data[0]["args2"];
				 // alert(DATEINFO+"\n"+DATEREVINFO)
				//当前选择月份天数 lqx 20190226
				var days = new Date(year,month,0);
				days = days.getDate();
				var min_date = $('input[name="min_date_num"]').val()?$('input[name="min_date_num"]').val():1;
				var max_date = $('input[name="max_date"]').val();
				var disabledays = $('input[name="disabledays"]').val().split(",");
				var disabledates = $('input[name="disabledates"]').val().split(",");
				
					var date = new Date();
                    date.setDate(date.getDate() + parseInt(min_date));
                    var new_month = date.getMonth() + 1;
                    var new_day = date.getDate();
					var new_year = date.getFullYear();
	                   var today2 = new Date();
	                   if(year == today2.getFullYear() && (month < today2.getMonth()+1) || year < today2.getFullYear()) {
	                	   thisDay = 32;
	                   } 
						
	                   $(".yue_rili .yue_day li").remove();
	                   for (i=0; i<startDay; i++) {$(".yue_rili .yue_day").append("<li></li>");}
						for (i=1; i<=days; i++) {
							var w_able = 1;
							//获取当前星期几
							var d = new Date(year,month-1,i);
							var wekday = d.getDay();
							// 机构星期几不能预约
							for(var j in disabledays){
								if(wekday === parseInt(disabledays[j])){
									w_able = 0;  //当前为不可预约天数
								}
							}
							var d_able = 1;
							var dates = year+'-'+month+'-'+i;
							// 机构不能预约的具体日期
							for(var k in disabledates){
								if(dates == disabledates[k]){
									d_able = 0;  //当前为不可预约天数
								}
							}
							var max_day = 1;
							if(max_date){
								var max_time = Date.parse(max_date);
								var now_time = Date.parse(dates);
								if(now_time > max_time){ //当前日期超过了最大可预约日期
									max_day = 0;
								}
							}

							var act = '';
							if(i == yfday && year==yfyear && month==yfmonth) {
								act = 'active';
							}
							if(d_able != 1 || w_able != 1 || max_day != 1){
								$(".yue_rili .yue_day").append("<li class='over " + act + "'>"+ i +"</li>");
							}
							else if(month == new_month && i < new_day){
								$(".yue_rili .yue_day").append("<li class='over " + act + "'>"+ i +"</li>");
							}else if(month == new_month && i >= new_day){
								var temp=year+"-"+(month<10?'0'+month:month)+"-"+(i<10?'0'+i:i);
								var textIsRev=getRevDayText(act,temp,i);
								$(".yue_rili .yue_day").append(textIsRev);
							}else if(month == new_month && i >= new_day){
								$(".yue_rili .yue_day").append("<li class='over " + act + "'>"+ i +"</li>");
							}else if(month < new_month){
								$(".yue_rili .yue_day").append("<li class='over " + act + "'>"+ i +"</li>");
							}//else if(i == thisDay&&year==today2.getFullYear()&&(month==today2.getMonth()+1)){
								//$(".yue_rili .yue_day").append("<li class='today " + act + "' style='background:#fff;'>"+ i +"<br><span>今天</span></li>");
							//}
							else if(month > new_month){
								var temp=year+"-"+(month<10?'0'+month:month)+"-"+(i<10?'0'+i:i);
								var textIsRev=getRevDayText(act,temp,i);
								$(".yue_rili .yue_day").append(textIsRev);
							}else if(month > new_month){
								$(".yue_rili .yue_day").append("<li class='over " + act + "'>"+ i +"</li>");
							}
						}
						$(".yue_rili").each(function(){
							var geshu=$(this).find(".yue_day li").length;
							if(28<geshu && geshu<35){
								for(var k=geshu;k<35;k++)
								{$(this).find(".yue_day").append("<li class='disabled'></li>");};
							}else if(35<geshu && geshu<42){
								for(var m=geshu;m<42;m++)
								{$(this).find(".yue_day").append("<li class='disabled'></li>");}
							}
						})
						if($(".banduansfy").hasClass("checklookrili")){
							$(".yue_rili .yue_day li.future").click(function(){
								$(".checklookrili").val($(this).attr("date"));
								$(".fixrilitmbg").fadeOut();
								$(".checklookrili").show();
							})
						}
						if(!$(".rilidiv").hasClass("unclick")){
							$(".yue_rili .yue_day li.future").click(function(){
								$(".yydata").val($(this).attr("date"));
								$(".fixrilitmbg").fadeOut();
							})
						}
						
						//$(".yue_rili .yue_day li a").fancybox({'autoScale':false});
				} 
	        );
	//end   通过json改变日历
  }

  var getRevDayText =function(text,temp,tempData,count){
     var textIsRev="&nbsp;";
	 
	 textIsRev= "<li class='future " + text + "' date="+temp+">"+ i +"<br>"+" <span id=ykbackrl_"+temp+"  class='zt1'>"+textIsRev+"</span>"+"</li>";

	return textIsRev;
  }
  
  var chushirili =function(today,year,month,thisDay,startDay){
	  //$(".shuchu").text(today+","+year+","+month+","+thisDay+","+startDay);
//	$("#xlyear option").attr("selected",false);
//	$("#xlyear option[id=y_"+year+"]").attr("selected",true);
//	$("#xlmonth option").attr("selected",false);
//	$("#xlmonth option[id=m_"+month+"]").attr("selected",true);
	  $("#xlyear").val(year);
	  $("#xlmonth").val(month); 
	var monthDays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) monthDays[1] = 29;
	daysOfCurrentMonth = monthDays[today.getMonth()];
	$(".yue_rili .yue_day li").remove();
	for (i=0; i<startDay; i++) {$(".yue_rili .yue_day").append("<li></li>");}
	/*for (i=1; i<=daysOfCurrentMonth; i++) {
		if (i < thisDay){
			$(".yue_rili .yue_day").append("<li class='over'>"+ i +"</li>");
		}else if(i == thisDay){
			$(".yue_rili .yue_day").append("<li class='today'>"+ i +"<br><span>今天<span></li>");
		}else{
			$(".yue_rili .yue_day").append("<li class='future' date="+year+"-"+month+"-"+i+">"+ i +"<br><span class='zt1'>可约</span></li>");
			
		}
	}*/
	//beg
	//var currDate=year+"-"+month+"-"+thisDay;
	initRiData(year,month,thisDay,startDay);
	//end
	
  }  
  
  $('.yf-setDate').click(function(e){
	  e.preventDefault();
	  var yftime = $('input[name=time]').val();
	  if(yftime) {
		  var dateTime = yftime.split('-');
		  today3 = new Date(dateTime[0]+"/"+dateTime[1]+"/01");
		  startDay3 = today3.getDay();
		  chushirili(today3,dateTime[0],dateTime[1],0,startDay3);
	  }
  });
}
var ykrili=new ykcalendar();

